import ajax from '../utils/ajax';

const form = document.forms.login;

form.onsubmit = function (e) {
    e.preventDefault();
    ajax('post', '/api/userlogin', { username: form.uid.value, password: form.pwd.value }).then(function (result) {
        if (result.flag) {
            // 登录成功，获取token并存储
            localStorage.setItem('token', result.data.token);
            alert(result.msg);
            location = '/index.html';
        } else {
            // 登录失败提示
            alert(result.msg);
            form.uid.select()
        }

    })

}